// 复利

public class CompoundInterest {
    public static void main(String[] args) {
        final double STARTRATE = 10;
        final int NRATES = 6;
        final int NYEARS = 10;

        // 设置各种利率 10 %, 11 %, ..., 15 %
        double[] interestRate = new double[NRATES];
        for (int i = 0; i < NRATES; i++) {
            interestRate[i] = (STARTRATE + i) / 100.0;
        }

        double[][] balances = new double[NYEARS][NRATES];

        // 初始化第一年在各种利率下的余额
        for (int i = 0; i < NRATES; i++) {
            balances[0][i] = 10000.0;
        }

        // 计算之后每一年在各种利率下的余额
        for (int i = 1; i < NYEARS; i++) {
            for (int j = 0; j < NRATES; j++) {
                double oldBalance = balances[i - 1][j];
                // 计算新余额
                double interest = oldBalance * interestRate[j];
                balances[i][j] = oldBalance + interest;
            }
        }

        // 打印各种利率
        for (int j = 0; j < NRATES; j++) {
            System.out.printf("%9.0f%%", 100 * interestRate[j]);
        }
        System.out.println();

        // 打印每一年在各种利率下的余额
        for (int i = 0; i < NYEARS; i++) {
            for (int j = 0; j < NRATES; j++) {
                System.out.printf("%10.2f", balances[i][j]);
            }
            System.out.println();
        }
    }
}
